<template>
  <el-time-picker
    v-model="inputVal"
    :disabled="isReadonly"
    @change="change"
    clearable
    :picker-options="pickerOptions"
    value-format="HH:mm:ss"
    :placeholder="`请选择${config.name}`"
  >
  </el-time-picker>
</template>
<script>
export default {
  props: {
    isReadonly: {
      type: Boolean,
      default: false,
    },
    formData: Object,
    config: {
      type: Object,
      default: () => Object.create(null),
    },
  },
  data() {
    return {
      inputVal: null,
      pickerOptions: {
        selectableRange: "00:00:00 - 23:59:59",
        format: "HH:mm:ss",
      },
    };
  },
  computed: {
    curVal() {
      return this.formData[this.config.prop] || "";
    },
  },
  watch: {
    curVal: {
      immediate: true,
      deep: true,
      handler(val) {
        this.inputVal = val;
      },
    },
  },
  methods: {
    change(val) {
      this.inputVal = val;
      this.formData[this.config.prop] = val;
      this.$emit("update:formData", this.formData);
      this.$emit("change", this.config.prop);
    },
  },
};
</script>
<style lang="scss" scoped></style>
